<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>抽奖</title>
		<script type="text/javascript">
			var data = "张XX,王XX,李XX,田XX,宋XX,赵XX,胡XX,孙XX,贾XX,何XX";
			var arr = data.split(",");//分拆抽奖的数据为数组
			var timer = 0;//定时器变量
			function start(){//开始抽奖程序
				if(!timer){
				//创建定时器
				timer = setInterval(function change(){
					var max = arr.length -1;//最大的下标数字
					var rand = Math.random();//随机数，小于0
					var randomIndex = parseInt(rand*max);//得到整型数据
					var d = document.getElementById("demo");
					d.innerHTML = arr[randomIndex];
				},50);
				}
			}
			function stop(){//停止按钮
				clearInterval(timer);//清除定时器
				timer = 0;
				var inputValue = document.getElementById("rst");//获取输入框的值
				var r = document.getElementById("demo");
				inputValue.value = r.innerHTML;//设置结果
				}
		</script>
	</head>
	<body>
		<div>请点击开始抽奖</div><br/>
		<button onclick="start()">开始抽奖</button>
		<button onclick="stop()">停止</button>
		<br/><br/>
		<div id="demo" name="demo"></div><br/>
		本轮抽奖结果为：<input type="text" id="rst" value="">
	</body>
</html>
